// packageE/signin/signin.js
var app = getApp();
const DrainageScene = require('../../../utils/drainage_scene.js')

Component({
  properties: {
    datas: {
      type: null
    },
    component_id: {
      type: null
    }
  },
  // 私有数据，可用于模板渲染
  data: {
    emptyImage: 'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png',
    clientWidth: '375',
    integral: '积分',
    clickTag: false,
    show: true,
    signdata: {}
  },

  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {
    },
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {
    if(this.data.datas.params) {
      this.setData({
        show: true,
        signdata: this.data.datas.params
      });
    }else {
      this.setData({
        show: false
      });
    }
    const value = wx.getStorageSync('integral');
    if (value) {
      this.setData({
        integral: value
      });
    }
  },

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },
  methods: {
    signnow(){
      let isBindDrainageScene = DrainageScene.bindDrainageScene({
        scene: 4,
        title: `${this.data.signdata.sign_name}`
      });
      if(!isBindDrainageScene) return;//爆客码绑定场景

      if (this.data.clickTag) {
        //防止快速点击
        return;
      }

      this.setData({
        clickTag: true
      });
      let urlStr = app.getNetAddresss('plugin.sign.Frontend.Modules.Sign.Controllers.sign.sign');
      app._postNetWork({
        url: urlStr,
        success: (resdata)=> {
          var res = resdata.data;
          if (res.result == 1) {
            this.getNum(res.msg);
            // this.setData({
            // 	'signdata.cumulative_number': this.data.signdata.cumulative_number + 1,
            // 	'signdata.sign_status': true
            // })
            // wx.showToast({
            // 	title: res.msg,
            // 	icon: 'none',
            // 	duration: 1500,
            // 	success: function() {
            // 		setTimeout(function() {
            // 			//要延时执行的代码
            // 		}, 1500) //延迟时间
            // 	},
            // })
          }else {
            wx.showToast({
              icon: 'none',
              title: res.msg,
              duration: 1500
            });
            setTimeout(()=> {
              this.setData({
                clickTag: false
              });
            }, 1000);
          }

        },
        fail: function(res) {
          console.log(res.msg);
        }
      });
    },
    getNum(msg){
      let urlStr = app.getNetAddresss('plugin.decorate.frotend.decorate-api.get-sign');
      app._postNetWork({
        url: urlStr,
        success: (resdata)=> {
          var res = resdata.data;
          if (res.result == 1) {
            this.setData({
              signdata: res.data,
              clickTag: false
            });
            wx.showToast({
              title: msg,
              icon: 'none',
              duration: 1500
            });
          }else {
            wx.showToast({
              icon: 'none',
              title: res.msg,
              duration: 1500
            });
            setTimeout(()=> {
              this.setData({
                clickTag: false
              });
            }, 1000);
          }

        },
        fail: function(res) {
          console.log(res.msg);
        }
      });
    },
  }
});
